﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

using SharedGenomics.Workbench.PresentationModel;

namespace SharedGenomics.Workbench.Views.WindowsForms
{
    public class CheckedComboBox : ToolStripControlHost
    {
        public CheckedComboBox()
            : base(new CheckedListBox() { CheckOnClick = true })
        {
            this.InitialiseComponent();
        }

        public CheckedListBox ListBox
        {
            get { return (CheckedListBox)this.Control; }
        }

        private void InitialiseComponent()
        {
            this.AutoSize = true;
        }

        public IEnumerable<ValueDisplayItem> Items
        {
            set
            {
                this.ListBox.Items.Clear();
                this.ListBox.Items.AddRange(value.Cast<object>().ToArray());
            }
        }

        public IEnumerable<object> SelectedValues
        {
            get
            {
                return this.ListBox.CheckedItems.Cast<ValueDisplayItem>().Select(vdi => vdi.Value);
            }
        }
    }
}
